<?php
/**
 * 微信推送消息.
 * User: lvshuyun
 * Date: 2015/6/11
 * Time: 10:24
 */

use kartik\grid\GridView;
use yii\helpers\Html;

$this->title = '微信推送消息';


$gridColumns = [
    ['class' => 'yii\grid\SerialColumn'],
    'title',
    'desc',
    'remark',
    'url',
    [
        'attribute' => 'money',
        'format' => 'raw',
        'value' => function($model) {
            return $model['money']/100;
        },

    ],
    [
        'attribute' => 'startTime',
        'format' => 'raw',
        'value' => function($model) {
            return date("Y-m-d H:i",$model['startTime']);
        },

    ],
    [
        'attribute' => 'endTime',
        'format' => 'raw',
        'value' => function($model) {
            return date("Y-m-d H:i",$model['endTime']);
        },

    ],
    [
        'attribute' => 'status',
        'format' => 'raw',
        'value' => function($model) {

            return $model->status ? '开启' : '关闭';
        },
        'filter' => [
            1 => '早',
            2 => '中',
            3 => '晚',
        ]
    ],
    [
        'attribute' => 'time',
        'format' => 'raw',
        'value' => function($model) {
            $label = [1=>'早',2=>'中',3=>'晚'];
            return isset($label[$model->time]) ? $label[$model->time] : '';
        },
        'filter' => [
            1 => '早',
            2 => '中',
            3 => '晚',
        ]
    ],
    [
        'label' => '操作',
        'format' => 'raw',
        'value' => function($model){
            $str = $model->status ? '关闭' : '开启';
            $output = Html::a('修改信息', \yii\helpers\Url::to(['wechat/send-edit', 'id'=>$model->id]), ['class'=>'btn btn-primary btn-xs']);
            $output .= '&nbsp; &nbsp; &nbsp;';
            $output .= Html::a($str, \yii\helpers\Url::to(['wechat/send-status', 'id'=>$model->id]), ['class'=>'btn btn-primary btn-xs']);
            return $output;
        },
    ],
];
    echo GridView::widget([
        'dataProvider' => $dataProvider,
        'toolbar' => [
            ['content' => Html::a('<i class="glyphicon glyphicon-plus"></i> 添加信息', ['wechat/send-add'], ['class' => 'btn btn-primary'])],
            '{toggleData}'
        ],
        'panel' => [
            'type' => GridView::TYPE_DEFAULT,
            'heading' => $this->title,
        ],
        'columns' => $gridColumns,
    ]);

